//
//  ViewController.m
//  UI_02homeworkNO1
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CocoTextField.h"
#import "CocoButton.h"






@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self creatLabels];
    [self creatTextFields];
    [self creatButtons];
}

// 创建Label类
-(void)creatLabels{
    
    //用户名
    UILabel *userName = [[UILabel alloc]initWithFrame:CGRectMake(65, 77, 80, 20)];
    userName.text = @"用户名";
    [self.view addSubview:userName];
    [userName release];
    // 密码
    UILabel *password = [[UILabel alloc]initWithFrame:CGRectMake(65, 127, 80, 20)];
    password.text = @"密码";
    [self.view addSubview:password];
    [password release];
    // 确认密码
    UILabel *confirmPassword = [[UILabel alloc]initWithFrame:CGRectMake(65, 177, 80, 20)];
    confirmPassword.text = @"确认密码";
    [self.view addSubview:confirmPassword];
    [confirmPassword release];
    // 手机号
    UILabel *phoneNumber = [[UILabel alloc]initWithFrame:CGRectMake(65, 227, 80, 20)];
    phoneNumber.text = @"手机号";
    [self.view addSubview:phoneNumber];
    [phoneNumber release];
    //邮箱
    UILabel *mailbox = [[UILabel alloc]initWithFrame:CGRectMake(65, 277, 80, 20)];
    mailbox.text = @"邮箱";
    [self.view addSubview:mailbox];
    [mailbox release];
    
}

// 创建UITextField类
-(void)creatTextFields{
    CocoTextField *userText = [[CocoTextField alloc]initWithFrame:CGRectMake(175, 75, 140, 30) withText:@"请输入用户名"];
    userText.delegate = self;
    [self.view addSubview:userText];
    [userText release];
    
    
    CocoTextField *passwordText = [[CocoTextField alloc]initWithFrame:CGRectMake(175, 125, 140, 30) withText:@"请输入密码"];
    passwordText.delegate = self;
    passwordText.secureTextEntry = YES;
    [self.view addSubview:passwordText];
    [passwordText release];
    
    CocoTextField *confirmText = [[CocoTextField alloc]initWithFrame:CGRectMake(175, 175, 140, 30) withText:@"再次输入密码"];
    confirmText.delegate = self;
    [self.view addSubview:confirmText];
    confirmText.secureTextEntry = YES;
    [confirmText release];
    CocoTextField *phoneText = [[CocoTextField alloc]initWithFrame:CGRectMake(175, 225, 140, 30) withText:@"请输入联系方式"];
    phoneText.keyboardType = UIKeyboardTypeNumberPad;
//    phoneText.delegate = self;
    [self.view addSubview:phoneText];
    [phoneText release];
    
    CocoTextField *mailText = [[CocoTextField alloc]initWithFrame:CGRectMake(175, 275, 140, 30) withText:@"请输入邮箱"];
    mailText.delegate = self;
    [self.view addSubview:mailText];
    [mailText release];

}
// 回收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

// 创建UIButton类
-(void)creatButtons{
    
    CocoButton *registerButton =[CocoButton buttonWithType:UIButtonTypeSystem withFrame:CGRectMake(80, 380, 50, 30) withText:@"注册"];
    [self.view addSubview:registerButton];
    [registerButton addTarget:self action:@selector(appearanceSuccessful:) forControlEvents:UIControlEventTouchUpInside];
   
    
    CocoButton *cancelButton = [CocoButton buttonWithType:UIButtonTypeSystem withFrame:CGRectMake(210, 380, 50, 30) withText:@"取消"];
    [self.view addSubview:cancelButton];
    [cancelButton addTarget:self action:@selector(cancelAllInput:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)appearanceSuccessful:(CocoButton *)button
{
    UIView *successView = [[UIView alloc]initWithFrame:self.view.frame];
    successView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:successView];
    UILabel *succeed = [[UILabel alloc]initWithFrame:CGRectMake(130, 230, 120, 40)];
    succeed.text = @"!!注册成功!!";
    [self.view addSubview:succeed];
    UIButton *returnButton = [UIButton buttonWithType:UIButtonTypeSystem];
    returnButton.frame = CGRectMake(30, 40, 60, 30);
    [returnButton setTitle:@"返回" forState:UIControlStateNormal];
    
    [successView addSubview:returnButton];
    [returnButton addTarget:self action:@selector(returnTheUpper:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)returnTheUpper:(UIButton *)button{

    UIView *newView = [[UIView alloc]initWithFrame:self.view.frame];
    newView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:newView];
    [newView release];
    
    [self creatLabels];
    [self creatTextFields];
    [self creatButtons];

}

-(void)cancelAllInput:(CocoButton *)button
{
    UIView *successView = [[UIView alloc]initWithFrame:self.view.frame];
    successView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:successView];
    [successView release];
    
    UILabel *succeed = [[UILabel alloc]initWithFrame:CGRectMake(40, 230, 290, 40)];
    succeed.text = @"突然发现问题是不会返回上一层";
    [self.view addSubview:succeed];
    [succeed release];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
